package cn.huaqingcheng.tianshu.common.core;

import org.jetbrains.annotations.Nullable;

/**
 * StrTool
 */
public interface StrTool {

    String EMPTY = "";

    static boolean isBank(@Nullable String str) {
        return str == null || str.trim().isBlank();
    }

    static boolean isNotBank(@Nullable String str) {
        return !isBank(str);
    }

    static boolean isEmpty(@Nullable String str) {
        return str == null || str.isEmpty();
    }

    static boolean isNotEmpty(@Nullable String str) {
        return !isEmpty(str);
    }

    static String valueOf(Object o) {
        return o == null ? EMPTY : o.toString();
    }

    static String firstNotEmpty(String str, String def) {
        return isEmpty(str) ? def : str;
    }

    static String firstNotEmpty(String str, String... def) {
        if (!isEmpty(str)) {
            return str;
        }

        for (String s : def) {
            if (!isEmpty(s)) {
                return s;
            }
        }

        throw new IllegalStateException();
    }

}
